package com.food.platformmanagement.adapter.inbound;

import com.food.platformmanagement.port.inbound.MemberUseCase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 24270
 */
@RestController
@RequestMapping(value = "/user")
@CrossOrigin("*")
public class UserController {
    private MemberUseCase useCase;

    @Autowired
    public UserController(MemberUseCase useCase) {
        this.useCase = useCase;
    }

    @GetMapping("/getAll")
    public List<UserDTO> getAllPlatformUser() {
        return useCase.getAllPlatformUser();
    }

    @GetMapping("/getOne/{id}")
    public UserDTO getTheUser(@PathVariable String id) {
        return useCase.getThePlatformUser(id);
    }

    @PostMapping("/add/{name}/{password}")
    public void add(@PathVariable String name, @PathVariable String password) {
        useCase.addPlatformUser(name, password);
    }

    @PostMapping("/change/name/{id}/{name}")
    public void changeName(@PathVariable String id, @PathVariable String name) {
        useCase.changeUserName(id, name);
    }

    @PostMapping("/change/password/{id}/{password}")
    public void changePassword(@PathVariable String id, @PathVariable String password) {
        useCase.changeUserPassword(id, password);
    }

    @PostMapping("delete/{id}")
    public boolean deleteUser(@PathVariable String id) {
        return useCase.deletePlatformUser(id);
    }
}
